#!/usr/local/bin/perl

#
# Prologue.
#

use iSOCK::Test::Prelude;

BEGIN {
  use iSOCK::Test::Setup;
  
  iSOCK::Test::Setup->setup;
}

#
# Modules.
#

use Roman;
use Test::WWW::Mechanize::Catalyst qw( iSOCK );
use XML::LibXML;

#
# Chapters.
#

my $dom      = XML::LibXML->load_xml ( location => "$ENV{PWD}/root/SOCK/doc/user_guide.xml", load_ext_dtd => 0 );
my @chapters = map { $_->textContent } $dom->findnodes ( '/book/chapter/title' );

#
# Plan.
#

plan tests => 2 + 2 + @chapters;

#
# Mech.
#

my $mech = Test::WWW::Mechanize::Catalyst->new;

$mech->timeout ( $mech->timeout * 2 );

#
# Login.
#

iSOCK::Test::Setup->login ( $mech );

#
# Documentation.
#

$mech->get_ok ( '/documentation' );
$mech->title_is ( 'iSOCK Documentation' );

my $i = 1;

for ( @chapters ) {
  my $r = uc roman ( $i++ );
  
  s/\s++/ \\s+ /g;
  
  $mech->content_like ( qr/Chapter \s+ $r\. \s+ $_/x )
}
